/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.perpus.View;

import com.perpus.Buku;
import com.perpus.Perpustakaan;
import com.perpus.Publikasi;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author admin
 */
public class TestPublikasiTableModel {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        ArrayList<Publikasi> test1 = new ArrayList<Publikasi>();
        Buku test11 = new Buku();
        try {
            test11.setIdKoleksi("1234567890");
            test11.setJudul("Pemrograman Java");
        } catch (Exception ex) {
            Logger.getLogger(TestPublikasiTableModel.class.getName()).log(Level.SEVERE, null,
                    ex);
        }
        Buku test12 = new Buku();
        try {
            test12.setIdKoleksi("1234567891");
            test12.setJudul("Struktur Data");
        } catch (Exception ex) {
            Logger.getLogger(TestPublikasiTableModel.class.getName()).log(Level.SEVERE, null,
                    ex);
        }
        test1.add(test11);
        test1.add(test12);
        Perpustakaan.TambahTabelPublikasi(test11);
        Perpustakaan.TambahTabelPublikasi(test12);
        String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
        String userid = "hr"; // gantikan dengan username anda
        String password = "hr"; // gantikan dengan password anda
        Connection conn;
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            conn = ds.getConnection(userid, password);
            System.out.println("Koneksi is OK");
            String sql = "select * from publikasi";
            Statement statement = conn.createStatement();
            ResultSet result = statement.executeQuery(sql);
            while (result.next() == true) {
                System.out.println(result.getString(1) + " " + result.getString(2));
            }
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
        }
    }
}
